package cz.cernilovsky.android.profileapp.activities;
import cz.cernilovsky.android.profileapp.R;
import cz.cernilovsky.android.profileapp.activities.LocationsActivity;
import cz.cernilovsky.android.profileapp.activities.MainActivity;
import cz.cernilovsky.android.profileapp.activities.ProfilesActivity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.*;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;


public class MainFragmentListActivity extends ListFragment {
	private static final int PROFILES_POSITION = 0;
	private static final int LOCATIONS_POSITION = 1;
	private static final int HELP_POSITION = 2;
	private static final int ABOUT_POSITION = 3;
	private static final String TAG = "MainFragmentListActivity";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		String[] objects = new String[4];
		objects[PROFILES_POSITION] = getString(R.string.profiles);
		objects[LOCATIONS_POSITION] = getString(R.string.locations);
		objects[HELP_POSITION] = getString(R.string.help);
		objects[ABOUT_POSITION] = getString(R.string.about_app);
		ListAdapter adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, objects);
		setListAdapter(adapter);
	}

	@Override
	public void onStart() {
		super.onStart();
		//Log.d(TAG, "onStart()");
		getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				Intent i = null;
				switch(position) {
				case PROFILES_POSITION:
					i = new Intent(getActivity(), ProfilesActivity.class);
					startActivity(i);
					break;
				case LOCATIONS_POSITION:
					i = new Intent(getActivity(), LocationsActivity.class);
					startActivity(i);
					break;
				case HELP_POSITION:
					Builder builder = new Builder(getActivity());
					builder.setTitle(R.string.help);
					builder.setMessage(R.string.help_message);
					builder.setCancelable(true);
					builder.create().show();
					break;
				case ABOUT_POSITION:
					builder = new Builder(getActivity());
					builder.setTitle(R.string.about_app);
					builder.setMessage(R.string.about_message);
					builder.setCancelable(true);
					builder.create().show();
					break;
				}
				
			}
		});
	}

}
